<template>
  <card class="box-card mb-20">
    <div slot="header">
      <span>单号数量警告模板</span>
      <submit-button class="float-right" ref="Submit" @submit="submit" text="保存"/>
    </div>
    <el-form :model="form" :rules="rules" ref="Form" label-width="100px" hide-required-asterisk>
      <el-form-item label="通知显示：" prop="money">
        <span>低于</span>
        <el-input-number
            v-model="form.money"
            class="w-200 ml-5"
            controls-position="right"
            placeholder="请输入单号数量"
            :precision="0"
            :min="0"/>
        <span class="ml-5">显示</span>
      </el-form-item>
      <el-form-item label="内容：" prop="content">
        <el-input v-model="form.content"></el-input>
      </el-form-item>
    </el-form>
  </card>
</template>

<script>
  import {editInformApi} from '@/api/website/inform'

  export default {
    name: "NumberWarning",
    data() {
      return {
        form: {
          id: 2,
          money: 0,
          content: ''
        },
        rules: {
          money: {required: true, message: '请输入单号数量', trigger: 'change'},
          content: {required: true, message: '请输入模板', trigger: 'blur'}
        }
      }
    },
    methods: {
      submit() {
        this.$refs['Form'].validate((valid) => {
          if (!valid) return false;
          let data = {...this.form};
          this.$refs.Submit.start();
          editInformApi(data).then(() => {
            this.$refs.Submit.stop();
            this.$emit('update');
          }).catch(() => {
            this.$refs.Submit.stop();
          })
        });
      }
    }
  }
</script>
